// pages/home/home.js
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    options:[]
  },

  myOrder(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/detail/detail?id='+id
    })
  },

  chooseType(e){
    var type = e.currentTarget.dataset.type
    wx.request({
      url: 'http://192.168.1.173:8080/api/item/list.do',
      data: {page:1,limit:50,itemType:type},
      dataType: "json",
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      method: "get",
      success: (result) => {
        that.setData({options:result.data.data})
      },
      fail: (res) => {},
      complete: (res) => {},
    })
  },

  showAll(e){
    wx.request({
      url: 'http://192.168.1.173:8080/api/item/list.do',
      data: {page:1,limit:50},
      dataType: "json",
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      method: "get",
      success: (result) => {
        that.setData({options:result.data.data})
      },
      fail: (res) => {},
      complete: (res) => {},
    })
  },

  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (block) {
    that = this;
    wx.request({
      url: 'http://192.168.1.173:8080/api/item/list.do',
      data: {page:1,limit:50},
      dataType: "json",
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      method: "get",
      success: (result) => {
        that.setData({options:result.data.data})
      },
      fail: (res) => {},
      complete: (res) => {},
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '加载中',
    })
    that = this;
    wx.request({
      url: 'http://192.168.1.173:8080/api/item/list.do',
      data: {page:1,limit:50},
      dataType: "json",
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      method: "get",
      success: (result) => {
        var oldL = that.data.options.length;
        var newL = result.data.data.length;

        wx.showToast({
          title: '加载成功'+(newL-oldL),
        })
        that.setData({options:result.data.data})
      },
      fail: (res) => {},
      complete: (res) => {
        setTimeout(function () {
          wx.hideLoading()
        }, 1000)
      },
    })

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})